import { Form, Input, message } from 'antd';
import CommonModal from '@/components/CommonModal';
import { useEffect } from 'react';
import { customTrimFunc } from '@/utils/utils.jsx';
import { costomizeAddressEdit } from '../service';

export default ({ customizeVisibleRemark, customizeCancel, handleStoreList, shopRemark, storeId, item }) => {
    const [form] = Form.useForm();

    const handleOk = () =>{
        form.validateFields().then(async val=>{
            const value = customTrimFunc(val).shopCustomAddress
            const { success, msg } = await costomizeAddressEdit({
                shopCustomAddress: value ? value : '',
                storeId,
                id: item?.id
            })
            if (success) {
                message.success(msg);
                customizeCancel();
                handleStoreList();
            }
        })
    }

    useEffect(()=>{
        form.setFieldsValue({
            shopCustomAddress: shopRemark
        })
    }, [shopRemark])

    return (
        <CommonModal
            title="修改备注"
            visible={customizeVisibleRemark}
            onOk={handleOk}
            onCancel={customizeCancel}
        >
            <Form form={form}>
                <Form.Item label="修改备注" name="shopCustomAddress">
                    <Input.TextArea placeholder='请输入门店备注，最多100个字符' maxLength={100} showCount style={{ height: 150 }} />
                </Form.Item>
            </Form>
        </CommonModal>
    )
}